package com.pro.service.imple;

import com.pro.mapper.JsLogMapper;
import com.pro.mapper.JsMicrocircleMapper;
import com.pro.pojo.JsLog;
import com.pro.pojo.JsMicrocircle;
import com.pro.service.JsMicrocircleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * ClassName:JsMicrocircleServiceImple
 * Package:com.pro.service.imple
 * Description:
 *
 * @Date:2022/1/7 11:27
 * @Author: ZPT
 */
@Service
public class JsMicrocircleServiceImple implements JsMicrocircleService {

    @Autowired(required = false)
    private JsMicrocircleMapper jsMicrocircleMapper;

    @Autowired(required = false)
    private JsLogMapper jsLogMapper;


    /**
     * @author ZPT
     * @date 2022/2/8 14:56
     * @content :查询微圈数据
     */
    @Override
    public List<JsMicrocircle> getMicrocircleTable(Integer acticleCategroyId, Integer page, Integer limit, String artcleTitle, String nickname, String account) {
        page = (page - 1) * limit;
        List<JsMicrocircle> microcircleList = jsMicrocircleMapper.getMicrocircleTable(acticleCategroyId, page, limit, artcleTitle, nickname, account);
        for (JsMicrocircle jsMicrocircle : microcircleList) {
            jsMicrocircle.setColCount(colCount(jsMicrocircle.getMicrocircleId()));
        }
        return microcircleList;
    }


    @Override
    public int colCount(Integer microcircleId) {
        return jsMicrocircleMapper.colCount(microcircleId);
    }

    @Override
    public Boolean deleteMicrocircle(Integer microcircleId, Integer userId) {
        Boolean aBoolean = jsMicrocircleMapper.deleteMicrocircle(microcircleId);
        if (aBoolean) {
            JsLog jsLog = new JsLog("js_microcircle", "3", userId, new Date(), "删除微圈", 3);
            jsLogMapper.addLog(jsLog);
        }
        return aBoolean;
    }

    @Override
    public JsMicrocircle getMicrocircleById(Integer microcircleId, Integer userId) {
        JsMicrocircle microcircle = jsMicrocircleMapper.getMicrocircleById(microcircleId);
        if (microcircle != null) {
            microcircle.setColCount(colCount(microcircleId));
            JsLog jsLog = new JsLog("js_microcircle", "5", userId, new Date(), "查看微圈详细", 3);
            jsLogMapper.addLog(jsLog);
        }
        return microcircle;
    }

    /**
     * @author ZPT
     * @date 2022/2/8 19:18
     * @content :微圈数量
     */
    @Override
    public Integer getCount(Integer acticleCategroyId, String artcleTitle, String nickname, String account){
        Integer count = jsMicrocircleMapper.getCount(acticleCategroyId,artcleTitle,nickname,account);
        return count;
    }

}
